🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / app / src / main / java / com / geeksville / mesh / service / MeshServiceStarter.kt
Displaying Raw • Download
app/src/main/java/com/geeksville/mesh/service/MeshServiceStarter.kt 78274c792318331b11ab64cd28e58e829875b8c2 (78274c79) Text, 1.98 KB
T8b949e/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787com.geeksville.mesh.service
Tff7b72import T7ee787android.app.ForegroundServiceStartNotAllowedException
Tff7b72import T7ee787android.content.Context
Tff7b72import T7ee787android.os.Build
Tff7b72import T7ee787com.geeksville.mesh.BuildConfig
Tff7b72import T7ee787timber.log.Timber
T8b949e// / Helper function to start running our service
Tff7b72fun Te6edf3MeshServiceTb4b4b4.Td2a8ffCompanionTb4b4b4.Te6edf3startServiceTb4b4b4(Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4) Tb4b4b4{
T8b949e// Bind to our service using the same mechanism an external client would use (for testing coverage)
T8b949e// The following would work for us, but not external users:
T8b949e// val intent = Intent(this, MeshService::class.java)
T8b949e// intent.action = IMeshService::class.java.name
T8b949e// Before binding we want to explicitly create - so the service stays alive forever (so it can keep
T8b949e// listening for the bluetooth packets arriving from the radio. And when they arrive forward them
T8b949e// to Signal or whatever.
Te6edf3TimberTb4b4b4.Te6edf3iTb4b4b4(Ta5d6ff"Ta5d6ffTrying to start service debug=Tffd700${Te6edf3BuildConfigTb4b4b4.Te6edf3DEBUGTffd700}Ta5d6ff"Tb4b4b4)
Tff7b72val Te6edf3intent Tff7b72= Te6edf3createIntentTb4b4b4(Te6edf3contextTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3BuildTb4b4b4.Te6edf3VERSIONTb4b4b4.Te6edf3SDK_INT Tff7b72>Tff7b72= Te6edf3BuildTb4b4b4.Te6edf3VERSION_CODESTb4b4b4.Te6edf3STb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Te6edf3contextTb4b4b4.Te6edf3startForegroundServiceTb4b4b4(Te6edf3intentTb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3exTb4b4b4: Te6edf3ForegroundServiceStartNotAllowedExceptionTb4b4b4) Tb4b4b4{
Te6edf3TimberTb4b4b4.Te6edf3eTb4b4b4(Ta5d6ff"Ta5d6ffUnable to start service: Tffd700${Te6edf3exTb4b4b4.Te6edf3messageTffd700}Ta5d6ff"Tb4b4b4)
Tb4b4b4}
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3contextTb4b4b4.Te6edf3startForegroundServiceTb4b4b4(Te6edf3intentTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.04s